

*** Set Fixed Effects and Clustering
global fe "courtq"
global clusvar "partyr"

*******************************
****** IV  & OLS Table ********
*******************************


capture frame drop credit
frame create credit str55 outcome str32 time str32 group str32 specification beta se N 

foreach g in all {
foreach spec in  ols rf iv meansd gmean emean {
	foreach out in indx_ avg_creditscore_ avg_zerorevolving_ any_autoloan_ avg_totbalcollect_ {

	if regexm("`out'", "creditscore")==1 {		
		global controls "female sh_hhpov lmrent logclaim notselfrep pre_avg_creditscore miss* "
	}
	if regexm("`out'", "zerorevolving")==1 {
		global controls "female sh_hhpov lmrent logclaim notselfrep preany_avg_zerorevolving miss*"		
	}
	if regexm("`out'", "auto")==1 {
		global controls "female sh_hhpov lmrent logclaim notselfrep preany_avg_autoloan miss*"		
	}
	if regexm("`out'", "totbalcollect")==1 {
		global controls "female sh_hhpov lmrent logclaim notselfrep pre_avg_totbalcollect miss*"		
	}
	if regexm("`out'", "indx")==1 {		
		global controls "female sh_hhpov lmrent logclaim notselfrep indx_pre miss*"
	}
	
	
	if "`spec'"=="ols" {
	*Run the regression
		reghdfe `out'q1q4 evictionorder $controls if samp==1 & `g'==1, absorb($fe) cluster($clusvar)
		frame post credit ("`out'") ("Q1Q4") ("`g'") ("`spec'") (_b[evictionorder]) (_se[evictionorder]) (e(N))

		reghdfe `out'q5q8 evictionorder $controls if samp==1 & `g'==1, absorb($fe) cluster($clusvar)
		frame post credit ("`out'") ("Q5Q8") ("`g'") ("`spec'") (_b[evictionorder]) (_se[evictionorder]) (e(N))

		reghdfe `out'q9q16 evictionorder $controls if samp==1 & `g'==1, absorb($fe) cluster($clusvar)
		frame post credit ("`out'") ("Q9Q16") ("`g'") ("`spec'") (_b[evictionorder]) (_se[evictionorder]) (e(N))

		reghdfe `out'q17q24 evictionorder $controls if samp==1 & `g'==1, absorb($fe) cluster($clusvar)
		frame post credit ("`out'") ("Q17Q24") ("`g'") ("`spec'") (_b[evictionorder]) (_se[evictionorder]) (e(N))

	}
		
	if "`spec'"=="iv" {
		ivreghdfe `out'q1q4 $controls (evictionorder =stringency) if samp==1 & `g'==1, absorb($fe) cluster($clusvar)
		gen tmpsamp`out'q1q4=(e(sample))	
		frame post credit ("`out'") ("Q1Q4") ("`g'") ("`spec'") (_b[evictionorder]) (_se[evictionorder]) (e(N))

		ivreghdfe `out'q5q8 $controls (evictionorder =stringency) if samp==1 & `g'==1, absorb($fe) cluster($clusvar)
		frame post credit ("`out'") ("Q5Q8") ("`g'") ("`spec'") (_b[evictionorder]) (_se[evictionorder]) (e(N))
		gen tmpsamp`out'q5q8=(e(sample))
		
		ivreghdfe `out'q9q16 $controls (evictionorder =stringency) if samp==1 & `g'==1, absorb($fe) cluster($clusvar)
		frame post credit ("`out'") ("Q9Q16") ("`g'") ("`spec'") (_b[evictionorder]) (_se[evictionorder]) (e(N))
		gen tmpsamp`out'q9q16=(e(sample))

		ivreghdfe `out'q17q24 $controls (evictionorder =stringency) if samp==1 & `g'==1, absorb($fe) cluster($clusvar)
		frame post credit ("`out'") ("Q17Q24") ("`g'") ("`spec'") (_b[evictionorder]) (_se[evictionorder]) (e(N))
		gen tmpsamp`out'q17q24=(e(sample))

	}

	if "`spec'"=="rf" {
		ivreghdfe `out'q1q4 $controls stringency if samp==1 & `g'==1, absorb($fe) cluster($clusvar)
		frame post credit ("`out'") ("Q1Q4") ("`g'") ("`spec'") (_b[stringency]) (_se[stringency]) (e(N))

		ivreghdfe `out'q5q8 $controls stringency if samp==1 & `g'==1, absorb($fe) cluster($clusvar)
		frame post credit ("`out'") ("Q5Q8") ("`g'") ("`spec'") (_b[stringency]) (_se[stringency]) (e(N))

		ivreghdfe `out'q9q16 $controls stringency if samp==1 & `g'==1, absorb($fe) cluster($clusvar)
		frame post credit ("`out'") ("Q9Q16") ("`g'") ("`spec'") (_b[stringency]) (_se[stringency]) (e(N))

		ivreghdfe `out'q17q24 $controls stringency if samp==1 & `g'==1, absorb($fe) cluster($clusvar)
		frame post credit ("`out'") ("Q17Q24") ("`g'") ("`spec'") (_b[stringency]) (_se[stringency]) (e(N))

	}

	if "`spec'"=="meansd" {
		sum `out'q1q4 if e(sample)==1 & evictionorder==0
		frame post credit ("`out'") ("Q1Q4") ("`g'")  ("`spec'") (`=r(mean)') (`=r(sd)') (r(N))

		sum `out'q5q8 if e(sample)==1 & evictionorder==0
		frame post credit ("`out'") ("Q5Q8") ("`g'")  ("`spec'") (`=r(mean)') (`=r(sd)') (r(N))

		sum `out'q9q16 if e(sample)==1 & evictionorder==0
		frame post credit ("`out'") ("Q9Q16") ("`g'")  ("`spec'") (`=r(mean)') (`=r(sd)') (r(N))

		sum `out'q17q24 if e(sample)==1 & evictionorder==0
		frame post credit ("`out'") ("Q17Q24") ("`g'")  ("`spec'") (`=r(mean)') (`=r(sd)') (r(N))

	}
	if "`spec'"=="gmean" {
		sum `out'q1q4 if e(sample)==1  
		frame post credit ("`out'") ("Q1Q4") ("`g'")  ("`spec'") (`=r(mean)') (`=r(sd)') (r(N))

		sum `out'q5q8 if e(sample)==1  
		frame post credit ("`out'") ("Q5Q8") ("`g'")  ("`spec'") (`=r(mean)') (`=r(sd)') (r(N))

		sum `out'q9q16 if e(sample)==1  
		frame post credit ("`out'") ("Q9Q16") ("`g'")  ("`spec'") (`=r(mean)') (`=r(sd)') (r(N))

		sum `out'q17q24 if e(sample)==1  
		frame post credit ("`out'") ("Q17Q24") ("`g'")  ("`spec'") (`=r(mean)') (`=r(sd)') (r(N))
	
		if "`spec'"=="emean" {
		sum evictionorder if e(sample)==1  
		frame post credit ("`out'") ("Q1Q4") ("`g'")  ("`spec'") (`=r(mean)') (`=r(sd)') (r(N))
		frame post credit ("`out'") ("Q5Q8") ("`g'")  ("`spec'") (`=r(mean)') (`=r(sd)') (r(N))
		frame post credit ("`out'") ("Q9Q16") ("`g'")  ("`spec'") (`=r(mean)') (`=r(sd)') (r(N))
		frame post credit ("`out'") ("Q17Q24") ("`g'")  ("`spec'") (`=r(mean)') (`=r(sd)') (r(N))

	}
	}
	}
}
}

frame change credit
replace time="Q01Q04" if time=="Q1Q4"
replace time="Q05Q08" if time=="Q5Q8"
replace time="Q09Q16" if time=="Q9Q16"
replace time="Q17Q24" if time=="Q17Q24"

gen out=""
replace out="CREDIT" if outcome=="avg_creditscore_"
replace out="ZERORV" if outcome=="avg_zerorevolving_"
replace out="AUTOLN" if outcome=="any_autoloan_"
replace out="COLECT" if outcome=="avg_totbalcollect_"
replace out="FINDEX" if outcome=="indx_"

replace out=out+time

replace outcome="Credit Score" if outcome=="avg_creditscore_"
replace outcome="Zero Revolving" if outcome=="avg_zerorevolving_"
replace outcome="Auto Loan" if outcome=="any_autoloan_"
replace outcome="Tot. Balance Collections" if outcome=="avg_totbalcollect_"
replace outcome="Index Financial Health" if outcome=="indx_"

replace specification=upper(specification)
frame credit: saveold ${Inputs}/NY_credit_ivols.dta, replace
frame change default




